<template>
  <!-- 添加或修改产成品库对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="采购方总部编码" prop="purchaserHqCode">
                <el-input v-model="form.purchaserHqCode" placeholder="请输入采购方总部编码"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="供应商编码" prop="supplierCode">
                <el-input v-model="form.supplierCode" placeholder="请输入供应商编码"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="供应商名称" prop="supplierName">
                <el-input v-model="form.supplierName" placeholder="请输入供应商名称"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="品类编码" prop="categoryCode">
                <el-input v-model="form.categoryCode" placeholder="请输入品类编码"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="种类编码" prop="subclassCode">
                <el-input v-model="form.subclassCode" placeholder="请输入种类编码"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="产成品库存数量" prop="productAmount">
                <el-input v-model="form.productAmount" placeholder="请输入产成品库存数量"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计量单位" prop="productUnit">
                <el-input v-model="form.productUnit" placeholder="请输入计量单位"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="物料编码" prop="eipMatCode">
                <el-input v-model="form.eipMatCode" placeholder="请输入物料编码"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="物资描述" prop="eipMatDes">
                <el-input v-model="form.eipMatDes" placeholder="请输入物资描述"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="规格型号" prop="speModels">
                <el-input v-model="form.speModels" placeholder="请输入规格型号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="电压等级" prop="voltageLevel">
                <el-input v-model="form.voltageLevel" placeholder="请输入电压等级"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="存放地点所在市" prop="storeCity">
                <el-input v-model="form.storeCity" placeholder="请输入存放地点所在市"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="入库时间" prop="putStorageTime">
                <el-date-picker clearable
                                v-model="form.putStorageTime"
                                type="date"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                placeholder="请选择入库时间">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="采购订单号" prop="poNo">
                <el-input v-model="form.poNo" placeholder="请输入采购订单号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="采购订单行项目ID" prop="poItemId">
                <el-input v-model="form.poItemId" placeholder="请输入采购订单行项目ID"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {addAction, getById, updateAction} from '@/api/manage';
import moment from 'moment';

export default {
  name: "FactoryLibraryProductForm",
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: "first",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      url: {
        getById: '/factoryLibraryProduct/factoryLibraryProduct/',
        add: '/factoryLibraryProduct/factoryLibraryProduct/add',
        edit: '/factoryLibraryProduct/factoryLibraryProduct/edit',
      },
    };
  },
  created() {

  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        purchaserHqCode: null,
        supplierCode: null,
        supplierName: null,
        categoryCode: "60",
        subclassCode: "60004",
        productAmount: null,
        productUnit: null,
        eipMatCode: null,
        eipMatDes: null,
        speModels: null,
        voltageLevel: null,
        storeCity: null,
        putStorageTime: null,
        poNo: null,
        poItemId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加产成品库";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getById(this.url.getById, id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改产成品库";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAction(this.url.edit, this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.$emit('ok');
            });
          } else {
            addAction(this.url.add, this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.$emit('ok');
            });
          }
        }
      });
    },
  }
};
</script>
